<template>
	<view class="main">
		<view class="basic-setting" v-if="basicSettingList.length > 0">
			<view class="basic-setting-title m-flex-row u-row-start u-p-t-26 u-p-b-26">
				<u-image :src="`${baseStaticFileUrl}/image/brand/basic-setting-icon.svg`" width="26rpx"
					height="26rpx" />
				<text class="u-font-26 u-m-l-8">基础设置</text>
			</view>

			<view class="basic-setting-list">
				<view class="basic-setting-item u-font-28 u-row-between u-p-l-26 u-p-r-26"
					v-for="(item,index) in basicSettingList" :key="index" @click="nav(item.url)">
					<view>{{item.title}}</view>
					<view class="basic-setting-item-r">
						<text v-if="item.haveSet">已设置</text>
						<text v-else class="basic-setting-item-r-t">未设置</text>
						<u-icon name="arrow-right" color="rgba(0, 0, 0, 0.5)" size="16"></u-icon>
					</view>
				</view>
			</view>

		</view>

		<view class="basic-setting" v-if="individuationList.length > 0">
			<view class="basic-setting-title m-flex-row u-row-start u-p-t-26 u-p-b-26">
				<u-image :src="`${baseStaticFileUrl}/image/brand/personalise.svg`" width="26rpx" height="26rpx" />
				<text class="u-font-26 u-m-l-8">个性化设置</text>
			</view>

			<view class="basic-setting-list">
				<view class="basic-setting-item u-font-28 u-row-between u-p-l-26 u-p-r-26"
					v-for="(item,index) in individuationList" :key="index" @click="nav(item.url)">
					<view>{{item.title}}</view>
					<view class="basic-setting-item-r">
						<text v-if="item.haveSet">已设置</text>
						<text v-else class="basic-setting-item-r-t">未设置</text>
						<u-icon name="arrow-right" color="rgba(0, 0, 0, 0.5)" size="16"></u-icon>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseStaticFileUrl: this.$configPath.staticFileUrl,
				basicSettingList: [
          {
            id: 1,
            title: '客服微信',
            url: '/pages-brand/brand/brand-info/brand-info-wechat',
            haveSet: false
          },
          {
            id: 2,
            title: '客服电话',
            url: '/pages-brand/brand/brand-info/brand-info-phone',
            haveSet: false
          },{
            id: 3,
            title: '营销广告',
            url: '/pages-brand/marketing-store/marketing-store',
            haveSet: false
          },
        ],

				individuationList: [{
						id: 1,
						title: '首页消息通知',
						url: '/pages-brand/brand/brand-info/brand-info-message',
            haveSet: false
					},
					{
						id: 2,
						title: '计量单位',
						url: '/pages-brand/measure-unit/measure-unit',
            haveSet: false
					}
				],

			}
		},
		onShow() {
      this.findCustomerServiceInfo();
      this.findMerchantBannerByUserId();
      this.findNoPageList();
    },
		onPullDownRefresh() {
      this.findCustomerServiceInfo();
      this.findMerchantBannerByUserId();
      this.findNoPageList();
      uni.stopPullDownRefresh();
		},
		methods: {

      // 客服微信、客服电话
      findCustomerServiceInfo() {
        this.$api('customerServiceInfo.findByUserIdList').then(res => {
          if (res.status == 0) {
            try {
              for (let i = 0; i < res.data.length; i++) {
                if (!this.$u.test.isEmpty(res.data[i].serviceName)){
                  this.basicSettingList[0].haveSet = true;
                }
              }
            } catch (e) {
              console.error(e.toString())
            }
            try {
              for (let i = 0; i < res.data.length; i++) {
                if (!this.$u.test.isEmpty(res.data[i].serviceMobilePhone) || !this.$u.test.isEmpty(res.data[i].serviceFixedTelephone)){
                  this.basicSettingList[1].haveSet = true;
                }
              }
            } catch (e) {
              console.error(e.toString())
            }
          } else {
            getApp().err('请求数据不成功:' + res.msg);
          }
        }).catch(err => {
          console.error(err.toString())
        })
      },

      // 判断广告是否已设置
			findMerchantBannerByUserId() {
				this.$api('merchantBanner.findMerchantBannerByUserId', null).then(res => {
					if (res.status == 0) {
            console.log("res.data",res.data)
						for (let i = 0; i < res.data.length; i++) {
							const item = res.data[i];
							if (item.merchantBannersList.length > 0) {
                this.basicSettingList[2].haveSet = true;
								break;
							}
						}
					} else {
						getApp().err('请求数据不成功:' + res.msg);
					}
				}).catch(err => {
          console.error(err.toString())
				})
			},


      // 客户端首页消息通知/计量单位
			findNoPageList() {
				this.$api('merchantStore.findNoPageList').then(res => {
          if (res.status == 0) {
						try {
              for (let i = 0; i < res.data.length; i++) {
                if (!this.$u.test.isEmpty(res.data[i].noticeMessageContentId) || !this.$u.test.isEmpty(res.data[i].noticeMessageTagId)) {
                  this.individuationList[0].haveSet = true;
                  break;
                }
              }
            } catch (e) {
              console.error(e.toString())
            }

            try {
              for (let i = 0; i < res.data.length; i++) {
                if (!this.$u.test.isEmpty(res.data[i].measuringUnit)) {
                  this.individuationList[1].haveSet = true;
                  break;
                }
              }
            } catch (e) {
              console.error(e.toString())
            }
					} else {
            getApp().err('请求数据不成功:' + res.msg);
          }
				}).catch(err => {
          console.error(err.toString())
				})
			},
      nav(url) {
        uni.navigateTo({
          url: url
        })
      },

    }
	}
</script>

<style lang="scss">
	.main {
		padding: 9rpx 24rpx 24rpx 24rpx;

		.basic-setting {
			.basic-setting-title {
				color: rgba(0, 0, 0, 0.7);
			}

			.basic-setting-list {
				width: 100%;
				background-color: #fff;
				border-radius: 20px;
				margin: 10px 0;

				.basic-setting-item {
					height: 122rpx;
					display: flex;
					flex-direction: row;

					.basic-setting-item-r {
						display: flex;
						flex-direction: row;

						.basic-setting-item-r-t {
							color: rgba(0, 0, 0, 0.5);
						}
					}
				}
			}
		}

	}
</style>
